using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Trigits
{
    public class TriominoeStack : TriominoeContainer
    {
        public TriominoeStack(Rectangle bounds, int max, SpriteFont font) : base(bounds, max, font)
        {
            int count = 0;
            Random rnd = new Random();

            for (int i = 0; i <= max; i++)
            {
                for (int j = i; j <= max; j++)
                {
                    for (int k = j; k <= max; k++)
                    {
                        triominoes[count] = new Triominoe(i, j, k, rnd.Next(360), false, font, 0.8f);
                        Vector2 loc = new Vector2(
                            rnd.Next(bounds.Width - (int)triominoes[count].getRadius()) + bounds.X + triominoes[count].getRadius(),
                            rnd.Next(bounds.Height - (int)triominoes[count].getRadius()) + bounds.Y + triominoes[count].getRadius());
                        triominoes[count].setLocation(loc);
                        count++;
                    }
                }
            }

            List<Triominoe> ordered = triominoes.ToList();
            List<Triominoe> shuffled = new List<Triominoe>(triominoes.Length);

            for (int i = 0; i < triominoes.Length; i++)
            {
                int next = rnd.Next(triominoes.Length - i);
                shuffled.Add(ordered.ElementAt(next));
                ordered.RemoveAt(next);
            }

            triominoes = shuffled.ToArray();
        }
    }
}
